#include <iostream>
#include <stdlib.h>

#include "managerview_console_impl.h"
#include "managerservice_impl.h"
#include "tools.h"

using namespace std;

ManagerViewConsoleImpl::ManagerViewConsoleImpl(void)
{
	service  = new ManagerServiceImpl;
}


void ManagerViewConsoleImpl::menu(void)
{
	while(1)
	{
		system("clear");
		cout<<"*****企业管理系统*****"<<endl;
		cout<<"1、增加管理员"<<endl;
		cout<<"2、删除管理员"<<endl;
		cout<<"3、列出所有管理员"<<endl;
		cout<<"0、返回上一级"<<endl;
		cout<<"------------------"<<endl;
		cout<<"请选择您的业务选项:";

		int choose;
		cin>>choose;
		switch(choose)
		{
			case ADD:add();break;
			case DEL:del();break;
			case LIST:list();break;
			case BACK:return;
		}
	}
}

void ManagerViewConsoleImpl::add(void)
{	
	int m_id =generator_MgrId();
	char temp_name[20];
	char temp_passwd[20];
	cout<<"请输入添加管理员用户名:";
	cin>>temp_name;
	cout<<"请输入密码:";
	cin>>temp_passwd;
	Manager manager(temp_name,temp_passwd,m_id);
	if(service->addManager(manager))
	{
		cout << "添加管理员用户成功" << endl;
	}
	else
	{
		cout << "添加管理员用户失败" << endl;
	}
	anykey_continue();
}

void ManagerViewConsoleImpl::del(void)
{
	int m_id = 0;
	cout<<"请输入要删除管理员的id:";
	cin>>m_id;
	if(service->deleteManager(m_id))
	{
		cout<<"删除管理员成功!" << endl;
	}
	else
	{
		cout << "该用户不存在,删除失败" << endl;
	}
	anykey_continue();

}

void ManagerViewConsoleImpl::list(void)
{
	service->listManager();
	anykey_continue();
}

ManagerViewConsoleImpl::~ManagerViewConsoleImpl(void)
{
	delete []service;
}
